package com.hzj.recipe.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzj.recipe.entity.Feedback;
import com.hzj.recipe.entity.Feedback;
import com.hzj.recipe.mapper.FeedbackMapper;
import com.hzj.recipe.service.FeedbackService;
import com.hzj.recipe.mapper.FeedbackMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
* @author 蜗牛菌
* @description 针对表【feedback(反馈表)】的数据库操作Service实现
* @createDate 2024-01-04 10:49:47
*/
@Service
public class FeedbackServiceImpl extends ServiceImpl<FeedbackMapper, Feedback>
    implements FeedbackService{

    @Autowired
    private FeedbackMapper feedbackMapper;

    @Override
    public Object listAll(Integer index, Integer size, Feedback feedback) {
        //默认第一页开始，每页5条
        if(index == null ||index==0){
            index=1;
        }
        if(size==null||size==0){
            size=5;
        }
        Page<Feedback> pageInfo = new Page(index, size);
        LambdaQueryWrapper<Feedback> lambdaQueryWrapper = new LambdaQueryWrapper();
        if (feedback.getFeedbackId() != null && feedback.getFeedbackId() != 0 && !Objects.equals(feedback.getFeedbackId(), "")) {
            lambdaQueryWrapper.eq(Feedback::getFeedbackId, feedback.getFeedbackId());
        }
        if (feedback.getUserId() != null && feedback.getUserId() != 0 && !Objects.equals(feedback.getUserId(), "")) {
            lambdaQueryWrapper.eq(Feedback::getUserId, feedback.getUserId());
        }
        if ((feedback.getFeedbackContent()!=null) && !Objects.equals(feedback.getFeedbackContent(), "")) {
            lambdaQueryWrapper.like(Feedback::getFeedbackContent, feedback.getFeedbackContent());
        }
        if (feedback.getFeedbackState() != null && !Objects.equals(feedback.getFeedbackState(), "")) {
            lambdaQueryWrapper.eq(Feedback::getFeedbackState, feedback.getFeedbackState());
        }
        
        Page<Feedback> feedbackPage = feedbackMapper.selectPage(pageInfo, lambdaQueryWrapper);
        return feedbackPage;
    }
}




